package com.browan.background;

import java.security.MessageDigest;

public class Md5Tool
{

	private static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
			'e', 'f' };

	public static String getMd5Value(String url)
	{
		if (url == null)
			return null;

		try
		{
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(url.getBytes());
			byte tmp[] = md.digest();

			char str[] = new char[32];

			for (int i = 0; i < 16; i++)
			{
				byte n = tmp[i];
				str[i * 2] = hexDigits[n >> 4 & 0xf];
				str[i * 2 + 1] = hexDigits[n & 0xf];
			}
			return new String(str); // 换后的结果转换为字符串

		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		return null;

	}

}
